package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.domain.vo.CartVO;
import com.dongdongshop.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("cart")
public class CartController {

    @Autowired
    private CartService cartService;

    //增加购物车
    @PostMapping("addCart")
    public Result addCart(@RequestParam Long skuId, @RequestParam Integer number,
                          @RequestHeader String AutharizeToken){
        cartService.addCart(skuId,number,AutharizeToken);
        return Result.OK();
    }

    //查询购物车
    @PostMapping("selectCart")
    public Result selectCart(@RequestHeader String AutharizeToken){
        List<CartVO> list = cartService.selectCart(AutharizeToken);
        return Result.OK().setData(list);
    }

    //删除购物车全部信息
    @PostMapping("delCart")
    public Result delCart(@RequestHeader String AutharizeToken){
        cartService.delCart(AutharizeToken);
        return Result.OK();
    }

}
